Aim: To build a 2D line, composed of a curve with flat sections to either side


In [41]:
import numpy as np
import matplotlib.pyplot as plt

In [42]:
Min_X = 0
Max_X = 8000
Amplitude = 800
Wavelength = 1600
SampleSpacing = 200
Range_X = Max_X - Min_X
NSamp = (Max_X - Min_X)/SampleSpacing

In [43]:
NSamp = (Max_X - Min_X)/SampleSpacing

In [44]:
# Fs = 8000
# f = 5
# sample = 16
# x = np.arange(sample)
# y = np.sin(2 * np.pi * f * x / Fs)
# plt.plot(x, y)
# plt.xlabel('voltage(V)')
# plt.ylabel('sample(n)')
# plt.show()

In [45]:
x = np.arange(Min_X, Max_X + SampleSpacing, SampleSpacing)
x


Out[45]:
array([   0,  200,  400,  600,  800, 1000, 1200, 1400, 1600, 1800, 2000,
       2200, 2400, 2600, 2800, 3000, 3200, 3400, 3600, 3800, 4000, 4200,
       4400, 4600, 4800, 5000, 5200, 5400, 5600, 5800, 6000, 6200, 6400,
       6600, 6800, 7000, 7200, 7400, 7600, 7800, 8000])

In [46]:
y = Amplitude * np.cos(2. * np.pi) + 1
y


Out[46]:
801.0

In [47]:
np.arange(5)


Out[47]:
array([0, 1, 2, 3, 4])

In [48]:
plt.plot(x, y)
plt.xlabel('voltage(V)')
plt.ylabel('sample(n)')
plt.show()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-48-d1983a05fb12> in <module>()
----> 1 plt.plot(x, y)
      2 plt.xlabel('voltage(V)')
      3 plt.ylabel('sample(n)')
      4 plt.show()

C:\Users\ee10sjo\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs)
   3097         ax.hold(hold)
   3098     try:
-> 3099         ret = ax.plot(*args, **kwargs)
   3100         draw_if_interactive()
   3101     finally:

C:\Users\ee10sjo\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\axes\_axes.pyc in plot(self, *args, **kwargs)
   1371         lines = []
   1372 
-> 1373         for line in self._get_lines(*args, **kwargs):
   1374             self.add_line(line)
   1375             lines.append(line)

C:\Users\ee10sjo\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\axes\_base.pyc in _grab_next_args(self, *args, **kwargs)
    302                 return
    303             if len(remaining) <= 3:
--> 304                 for seg in self._plot_args(remaining, kwargs):
    305                     yield seg
    306                 return

C:\Users\ee10sjo\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\axes\_base.pyc in _plot_args(self, tup, kwargs)
    280             x = np.arange(y.shape[0], dtype=float)
    281 
--> 282         x, y = self._xy_from_xy(x, y)
    283 
    284         if self.command == 'plot':

C:\Users\ee10sjo\AppData\Local\Continuum\Anaconda\lib\site-packages\matplotlib\axes\_base.pyc in _xy_from_xy(self, x, y)
    221         y = np.atleast_1d(y)
    222         if x.shape[0] != y.shape[0]:
--> 223             raise ValueError("x and y must have same first dimension")
    224         if x.ndim > 2 or y.ndim > 2:
    225             raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension

In [ ]: